﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using System.Collections;
using System.Data;
namespace AirPlane
{
    public partial class TraCuuChuyenBay : System.Web.UI.Page
    {
        protected SanBayBUS sb = new SanBayBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                datepickerdepart.Text = DateTime.Now.ToShortDateString();
                datepickergoing.Text = DateTime.Now.AddDays(3).ToShortDateString();
                ddlSanBayDi.DataSource = sb.loadSanBayDi();
                ddlSanBayDi.DataBind();
                ddlSanBayDen.DataSource = sb.loadSanBayDen();
                ddlSanBayDen.DataBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ChuyenBayBUS bus = new ChuyenBayBUS();
            DataTable dt = new DataTable();
            DataTable dt1 = new DataTable();
            lbChuyenBayDi.Text = "";
            lbChuyenBayVe.Text = "";
            gwChuyenBayDi.DataSource = null;
            gwChuyenBayDi.DataBind();
            gwChuyenBayVe.DataSource = null;
            gwChuyenBayVe.DataBind();
            int type = int.Parse(RadioButtonList1.SelectedValue.ToString());
            int condition = int.Parse(ddlTieuChi.SelectedValue.ToString());
            if (condition == 0)
            {
                dt = bus.TimKiemChuyenBay(ddlSanBayDi.SelectedValue.ToString(), ddlSanBayDen.SelectedValue.ToString(), datepickerdepart.Text, "sp_TimChuyenBayTheoNhieuTieuChi");
                if (dt.Rows.Count == 0)
                {
                    lbChuyenBayDi.Text = "<span id = 'thong-bao-ket-Qua-Tim-Kiem'>Không Tìm Thấy Thông Tin Chuyến Bay Đi</span>";
                }
                else
                {
                    lbChuyenBayDi.Text = "<span id='title-tim-kiem'>CHUYẾN BAY ĐI</span>";
                    gwChuyenBayDi.DataSource = dt;
                    gwChuyenBayDi.DataBind();
                }
                if (type == 1)
                {
                    dt1 = bus.TimKiemChuyenBay(ddlSanBayDen.SelectedValue.ToString(), ddlSanBayDi.SelectedValue.ToString(), datepickergoing.Text, "sp_TimChuyenBayTheoNhieuTieuChi");
                    if (dt1.Rows.Count == 0)
                    {
                        lbChuyenBayVe.Text = "<span id = 'thong-bao-ket-Qua-Tim-Kiem'>Không Tìm Thấy Thông Tin Chuyến Bay Về</span>";
                    }
                    else
                    {
                        lbChuyenBayVe.Text = "<span id='title-tim-kiem'>CHUYẾN BAY VỀ</span>";
                        gwChuyenBayVe.DataSource = dt1;
                        gwChuyenBayVe.DataBind();
                    }
                }
            }
            else
                if (condition == 1)
                {
                    dt = bus.TimKiemChuyenBayTheoTieuChi(ddlSanBayDi.SelectedValue.ToString(), datepickerdepart.Text, "sp_TimChuyenBayTheoSanBayDi");
                    if (dt.Rows.Count == 0)
                    {
                        lbChuyenBayDi.Text = "<span id = 'thong-bao-ket-Qua-Tim-Kiem'>Không Tìm Thấy Chuyến Bay Nào!</span>";
                    }
                    else
                    {
                        lbChuyenBayDi.Text = "<span id='title-tim-kiem'>CHUYẾN BAY ĐƯỢC TÌM THẤY</span>";
                        gwChuyenBayDi.DataSource = dt;
                        gwChuyenBayDi.DataBind();
                    }
                    
                }
                else
                {
                   
                    dt1 = bus.TimKiemChuyenBayTheoTieuChi(ddlSanBayDen.SelectedValue.ToString(), datepickerdepart.Text, "sp_TimChuyenBayTheoSanBayDen");
                    if (dt1.Rows.Count == 0)
                    {
                        lbChuyenBayVe.Text = "<span id = 'thong-bao-ket-Qua-Tim-Kiem'>Không Tìm Thấy Chuyến Bay Nào!</span>";
                    }
                    else
                    {
                        lbChuyenBayVe.Text = "<span id='title-tim-kiem'>CHUYẾN BAY ĐƯỢC TÌM THẤY</span>";
                        gwChuyenBayVe.DataSource = dt1;
                        gwChuyenBayVe.DataBind();
                    }
                }
           
        }
    }
}